﻿using Ext.Net;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class CRM_Manager_ERP_SalesPlanSelect : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ViewState_OrderSre = "InDate desc";
            exthidn_CustomerID.Text = Request.QueryString["customerId"];
            var cModel = CRMMis.BLL.ERP_Customer.GetModel(Convert.ToInt32(exthidn_CustomerID.Text));
            exttextf_Customer.Text = cModel.CustomerName;
            exthidn_StoreRoomID.Text = Request.QueryString["storeroomId"];
            var row = CommonLib.BLL.BS_DATASET_SQL.SqlGetTable(" select * from VIEW_STORE where STOREROOM_ID="+ exthidn_StoreRoomID.Text).Rows[0];
            exttextf_StoreRoomName.Text = row["STOREROOM_NAME"].ToString();

            gridPanel_listdata.Reload();
        }

    }

    string _QueryString;
    private string GetQryString()
    {
        string result = " 1=1 and state=2 and StoreRoomId="+ exthidn_StoreRoomID.Text+ " and CustomerId="+ exthidn_CustomerID.Text;
        if (exttxtf_SalesPlanNo.Text.Trim() != "")
            result += " and SalesPlanNo like'%" + FilterSpecChar(exttxtf_SalesPlanNo.Text.Trim()) + "%'";
        //if (exttxtf_Creater.Text.Trim() != "")
        //    result += " and CreaterName like'%" + FilterSpecChar(exttxtf_Creater.Text.Trim()) + "%'";
        return result;
    }

    protected void MyData_Refresh(object sender, StoreRefreshDataEventArgs e)
    {
        _QueryString = GetQryString();
        int count = CRMMis.BLL.ERP_SalesPlan.GetRecorderCount(_QueryString);
        BindGridPSData(e, ViewState_OrderSre, PagingToolbar1, Store1, count);
    }

    public override DataTable GetPSData(int PageSize, int CurPage, string OrderStr)
    {
        ViewState_OrderSre = OrderStr;
        DataTable dt = CRMMis.BLL.ERP_SalesPlan.GetPageList(PageSize, CurPage, _QueryString, OrderStr).Tables[0];
        return dt;
    }
}